/*
     Copyright (C) 2011 Benny Mackney

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef VEC2D_H
#define VEC2D_H

#include "bennysc.h"
#include <math.h>


class Vec2D
{
    public:
        //! Constructor of zero/null vector
        Vec2D();
        //! Constructor for vector with values
        Vec2D(double newX, double newY);
        virtual ~Vec2D();
        //Operators
        //! Adds another vector to this one
        Vec2D & operator+=(const Vec2D &other);
        //! Subtracts another vector from this one
        Vec2D & operator-=(const Vec2D &other);
        //! Used to add two vectors
        Vec2D operator+(const Vec2D &rhs);
        //! Used to subtract two vectors
        Vec2D operator-(const Vec2D &rhs);
        //const funcs
        //! Returns the length of the vector
        double length() const;
        //! Returns the squared length of the vector
        /*!
            This function can be used instead of length() to avoid a square root function that might not be needed (e.g. for comparision of distances)
        */
        double length2() const;
        //! Returns the angle the vector is pointing
        /*!
            Uses radians. 0 is right, clockwise positive
        */
        double angle() const;
        //! Returns the x value of the vector
        double get_x() const;
        //! Returns the y value of the vector
        double get_y() const;
        //nonconst funcs
        //! Sets new values for the vector
        void set(double newX, double newY);
        void set_x(double newX);
        void set_y(double newY);
        //! Multiplies the length of the vector
        void scale(double multiplier);
        //! Scales the vector so that it becomes endLength long
        void scale_to(double endLength);
        //! Rotates the vector
        void rotate(double angleShift);
        //! Rotates the vector around a point
        void rotate_around(const Vec2D &axis,double angleShift);


    protected:
    private:
        double x;
        double y;
};

#endif // VEC2D_H
